package com.example.controller;

import com.example.model.Goods;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    private  List<Goods> goodsList = new ArrayList<>();


    /**
     * 获取所有的商品信息
     */
    @RequestMapping("/list")
    public List<Goods> list(){
        Goods goods = new Goods("1", "小米", "1999");
        Goods goods2 = new Goods("2", "OPPO", "2999");
        Goods goods3 = new Goods("3", "华为", "3999");
        goodsList.add(goods);
        goodsList.add(goods2);
        goodsList.add(goods3);
        return goodsList;
    }


    /**
     * 接收添加商品的表单数据
     */
    @RequestMapping("/add")
    public String add(Goods goods){
       goodsList.add(goods);
       return "添加商品成功";
    }
}
